package dao;

import java.util.List;
import entity.CheckIn;

public class CheckInDao {

	public List<CheckIn> select(String where) {
		return DbHepler.executeQuery("select t1.*, t2.name user_name, t3.name from CheckIn t1 "
				+ "inner join User t2 on t1.user_id=t2.id "
				+ "inner join Room t3 on t1.room_id=t3.id "+where, CheckIn.class);
	}
    
	public int insert(CheckIn model) {
		return DbHepler.executeUpdate("insert into CheckIn ("
				+ "date,"
				+ "user_id,"
				+ "room_id,"
				+ "exitdate,"
				+ "outdate,"
				+ "amount,"
				+ "yamount,"
				+ "status,"
				+ "comments) values(?,?,?,?,?,?,?,?,?)", 
				model.getDate(),
				model.getUser_id(),
				model.getRoom_id(),
				model.getExitString(),
				model.getOutdate(),
				model.getAmount(),
				model.getYamount(),
				model.getStatus(),
				model.getComments());
	}
	
	public int update(CheckIn model) {
		return DbHepler.executeUpdate("update CheckIn set "
				+ "date=?,"
				+ "user_id=?,"
				+ "room_id=?,"
				+ "exitdate=?,"
				+ "outdate=?,"
				+ "amount=?,"
				+ "yamount=?,"
				+ "status=?,"
				+ "comments=?", 
				model.getDate(),
				model.getUser_id(),
				model.getRoom_id(),
				model.getExitString(),
				model.getOutdate(),
				model.getAmount(),
				model.getYamount(),
				model.getStatus(),
				model.getComments());
	}
	
	public int delete(int id) {
		return DbHepler.executeUpdate("delete from CheckIn where id=?", id);
	}
	
	public CheckIn getbyid(int id) {
		List<CheckIn> list=DbHepler.executeQuery("select t1.*, t2.name user_name, t3.name from CheckIn t1 "+ 
				"inner join User t2 on t1.user_id=t2.id " + 
				"inner join Room t3 on t1.room_id=t3.id where id=?", CheckIn.class,id);
		return list.get(0);
	}
	
}
